<?php
/**
	新闻模块
*/
if(empty($_GET['nid'])){	?>
<ul style="margin:0;padding:0;display:table;width:100%;">
<?php
$sql="select * from ".DB_PREFIX."pages where isNews=1 order by sort desc";
$query=mysql_query($sql);
$num_all=mysql_num_rows($query);
$page_size=10;
$page_count=ceil($num_all/$page_size);
$offset=$page_size*intval(!empty($_GET['page'])?($_GET['page']-1):0);
$sql="select * from ".DB_PREFIX."pages where isNews=1 order by time desc,sort desc limit ".$offset." , ".$page_size;
$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num>0){
	while($arr=mysql_fetch_array($query)){
		parse_str($_SERVER['QUERY_STRING'],$myArray);
		$myArray['nid']=$arr['id'];
		$nurl= "./list.php?".http_build_query($myArray);
		echo '<li style="list-style-type:none;width:100%;height:30px;line-height:30px;"><div style="width:60%;float:left;text-align:left;"><a onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" href="'.$nurl.'">'.$arr['title'].'</a></div><div style="width:30%;float:right;text-align:right;color:#666;">'.date('Y-m-d H:i:s',$arr['time']).'</div></li>';	
	}
}
?>	
</ul>
<div style="text-align:center"><a href="<?php
	if(intval($_GET['page'])>1){
	parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=$_GET['page']-1;
		echo "./list.php?".http_build_query($myArray);}?>
	">上一页</a>&nbsp;<a href="<?php
		if((intval($_GET['page'])<$page_count) && ($num_all>$page_size)){
		parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=(empty($_GET['page'])?1:$_GET['page'])+1;
		echo "./list.php?".http_build_query($myArray);}?>
		">下一页</a>，<?php if(empty($page_count)){echo '0';}else{echo empty($_GET['page'])?1:intval($_GET['page']);} ?> / <?php echo $page_count; ?></div>
<?php
}else{
	$sql="select * from ".DB_PREFIX."pages where id=".intval($_GET['nid']);
	$query=mysql_query($sql);
	$num=mysql_num_rows($query);
	if($num>0){
	$arr=mysql_fetch_array($query);
	echo "<div style='text-align:center'><p><span style='font-weight:bold;'>".$arr['author']."</span><span style='font-weight:normal;margin:0 10px;'>发表于</span><span style='font-weight:bold;'>".date('Y-m-d H:i:s',$arr['time'])."</span></p></div>";
	echo "<p>".htmlspecialchars_decode($arr['content'])."</p>";
	}
}
?>